<div class="container-fluid">
    <div class="wrapper">
        <div class="panel" id="nav">
            <div class="panel-heading"><h3 class="panel-title">不良品实物确认处理</h3></div>
            <div class="panel-body">
                <form action="__URL__/handlequality" method="get">
                    <div class="container-fluid">
                        <div class="col-sm-12 col-md-3  add-space">
                            <div class="input-group input-group-md">
                                <span class="input-group-addon">采购单号</span>
                                <input class="form-control" type="text" name="purchaseorder_id">
                            </div>
                        </div>
                        <div class="col-sm-12 col-md-3  add-space">
                            <div class="input-group input-group-md">
                                <span class="input-group-addon">供应商</span>
                                <input type="text" name="supplier" class="form-control" value="">
                            </div>
                        </div>
                        <div class="col-sm-12 col-md-3  add-space">
                            <div class="input-group input-group-md">
                                <span class="input-group-addon">SKU</span>
                                <input class="form-control" type="text" name="sku">
                            </div>
                        </div>
                        <div class="col-sm-12 col-md-3  add-space">
                            <div class="input-group input-group-md">
                                <span class="input-group-addon">站点</span>
                                <select class="chosen-select form-control" tabindex="-1" name="site_id" data-name-group="common">
                                    <option value="" class="empty-opt">-- 请选择 --</option>
                                    <volist name="sites" id="item">
                                        <option value="{$key}">{$item}</option>
                                    </volist>
                                </select>
                            </div>
                        </div>
                        <div class="col-sm-12 col-md-3  add-space">
                            <div class="input-group input-group-md">
                                <span class="input-group-addon">采购员</span>
                                <input type="text" name="purchase_man" class="form-control" value="">
                            </div>
                        </div>
                        <div class="col-sm-12 col-md-6  add-space">
                            <div class="input-group input-group-md">
                                <span class="input-group-addon">处理日期</span>
                                <input class="form-control form-date" type="text" name="deal_time_from"
                                       style="cursor:pointer;" readonly>
                                <span class="input-group-addon"><span class="icon-calendar"></span></span>
                                <input class="form-control form-date" type="text" name="deal_time_to"
                                       style="cursor:pointer;" readonly>
                            </div>
                        </div>
                        <div class="col-sm-12 col-md-3  add-space">
                            <div class="input-group input-group-md">
                                <span class="input-group-addon">处理方式</span>
                                <select class="chosen-select form-control" tabindex="-1" name="fail_deal_way"
                                        data-name-group="common">
                                    <option value="" class="empty-opt">-- 请选择 --</option>
                                    <volist name="status" id="item">
                                        <option value="{$key}">{$item}</option>
                                    </volist>
                                </select>
                            </div>
                        </div>
                        <div class="col-md-3 add-space">
                            <input class="btn btn-primary" type="submit" value="查询">
                            <input class="btn btn-primary" type="button" onclick="reset()" value="重置">
                            <!--<input class="btn btn-primary" type="submit" name="downcsv" value="下载">-->
                        </div>
                    </div>
                </form>
                <div class="clearfix"></div>
                <hr>
                <table class="table" cellspacing="0" width="100%">
                    <tbody>
                    <volist name="result" id="val" key="key">
                        <tr style="background-color:lightgrey;font-weight:bold; color: #113333;">
                            <th style="width:80px;">不良品出库表单号</th>
                            <th style="width:100px;">不良品处理单号</th>
                            <th style="width:150px;">采购单号</th>
                            <th style="width:250px;">SKU</th>
                            <th style="width:18%;">中文名称</th>
                            <th style="width:200px;">供应商</th>
                            <th style="width:100px;">不合格数量</th>
                            <th style="width:190px;">质检不合格原因</th>
                            <th style="width:190px;">质检人</th>
                            <th style="width:190px;">站点</th>
                        </tr>
                        <tr>
                            <td>{$val.id}</td>
                            <td>{$val.unqualified_id}</td>
                            <td>{$val.purchaseorder_id}</td>
                            <td>{$val.sku}</td>
                            <td>{$val.sku_name}</td>
                            <td>{$val.supplier}</td>
                            <td>{$val.quantity}</td>
                            <td>{$val.remark}</td>
                            <td>{$val.check_man}</td>
                            <td>{$val.site_id}</td>
                        </tr>
                        <tr style="background-color:rgba(129,208,177,.3);">
                            <th>采购员</th>
                            <th>处理人</th>
                            <th>实物出库备注</th>
                            <th>采购处理方式</th>
                            <th>采购处理备注</th>
                            <th>质检时间</th>
                            <th>处理时间</th>
                            <th>状态</th>
                            <th></th>
                            <th>操作</th>
                        </tr>
                        <tr style="background-color:#ffffff;">
                            <td>{$val.purchase_man}</td>
                            <td>{$val.operate_man}</td>
                            <if condition="$val['status'] eq '未处理'">
                            <td><input type="text" class="w100 form-control" id="remark_{$val.id}"/></td>
                                <else/>
                                <td>{$val.warehouse_remark}</td>
                            </if>
                            <td>{$val.fail_deal_way}</td>
                            <td>{$val.unqualified_reason}</td>
                            <td>{$val.invoice_date}</td>
                            <td>{$val.deal_time}</td>
                            <td>{$val.status}</td>
                            <td></td>
                            <if condition="$val['status'] eq '未处理'">
                                <td><button type="button" class="btn btn-xs btn-info b10 tijiao_detail"  data-toggle="modal" data-target=".btn_edit" data-id="{$val.id}">提交
                                </button></td>
                                <elseif condition="$val['status'] eq '已处理' AND $val['print_status'] eq 2"/>
                                <td><button type="button" class="btn btn-xs btn-success print"  data-toggle="modal" data-target=".btn_edit" data-id="{$val.id}">打印
                                <elseif condition="$val['status'] eq '已处理' AND $val['print_status'] eq 1"/>
                                <td><button type="button" class="btn btn-xs btn-success print"  data-toggle="modal" data-target=".btn_edit" data-id="{$val.id}">已打印
                                </button></td>
                            </if>
                            <td></td>
                        </tr>
                    </volist>
                    </tbody>
                </table>

                <div class="clearfix clear"></div>
                <div class="row">
                    <div class="col-md-6 pull-left">
                        <label>每页 20 条记录
                            显示 1 到 20 项，共 {$count}项</label>
                    </div>
                    <div class="col-md-6">
                        <div class="page pull-right" style="padding: 0;margin: 0">
                            {$page}
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    $(function () {
        $("input[name='purchaseorder_id']").val("<?php  echo $_GET['purchaseorder_id'];?>");
        $("input[name='supplier']").val("<?php echo $_GET['supplier'];?>");
        $("input[name='sku']").val("<?php echo $_GET['sku'];?>");
        $("input[name='purchase_man']").val("<?php  echo $_GET['purchase_man'];?>");
        $("input[name='check_time_from']").val("<?php  echo $_GET['check_time_from'];?>");
        $("input[name='check_time_to']").val("<?php echo $_GET['check_time_to'];?>");
        $("select[name='site_id']").val("<?php echo $_GET['site_id'];?>");
        $("select[name='fail_deal_way']").val("<?php echo $_GET['fail_deal_way'];?>");
    });
    /**
     * 重置
     * */
    function reset() {
        $('#form_search').find('input').val('');
        $('#form_search').find('select').val('');
    }

    $(".tijiao_detail").click(function(){
        $(this).css('display','none');
        var id = $(this).attr("data-id");
        var warehouse_remark = $("#remark_"+id).val();
        $.get("Warehouse/BadProducts/tijiao",
                {
                    id: id,
                    warehouse_remark: warehouse_remark
                },
                function (data) {
                    if (data.status == 0) layer.msg(data.info);
                    var obj = jQuery.parseJSON(data);
                    if (obj.status == 'Y') {
                        layer.msg(obj.message, {icon: 6});
                        window.location.reload();
                    } else {
                        layer.msg(obj.message, {icon: 5});
                    }
                });
    });
    $(".print").click(function () {
        var id = $(this).attr("data-id");
        window.location.href = '__URL__/printquality?id=' + id;
    });
    function download_csv() {
        var param = search_params();
        window.location.href = '__URL__/index?downcsv=1' + param;
    }

</script>
